<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="UTF-8" />
    <title>中汽中心智慧办公平台</title>
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link rel="stylesheet" href="libs/layui/css/layui.css">
    <link rel="stylesheet" href="css/newsList.css">
    <script src="libs/jquery_1.9.1.min.js"></script>
    <script src="libs/layui/layui.all.js"></script>
    <script src="libs/common.js"></script>

    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>

</head>

<body class="layui-layout-body">
    <div class="layui-layout">
        <div class="header">
            <h1 class="logo">
                <img src="./images/logo1.png">
                <span>中汽中心智慧办公平台 </span>
            </h1>
            <nav class="header-nav">
                <div class="nav-date" id="dateStr"></div>
                <!-- <div class="nav-weather">
                  <img id="weaimg" src="http://tq.daodaoim.com//tianqiapi/skin/pitaya/undefined.png" alt="">
                  <span id="wea">晴</span>
                </div> -->
            </nav>
        </div>

        <div class="main">
            <div>
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="card mt20 todo-list">
                            <div class="card-title">
                                <h4>内部资讯</h4>
                            </div>
                            <div class="card-content">
                                <div class="content-inner">
                                    <ul style="display: block;" id="content">
                                    </ul>
                                </div>
                            </div>

                            <div>
                                <div id="pager" style='text-align:right'></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <script>
        $(document).ready(function () {

            // 获取数据url
            var DATA_URL = 'https://portal.catarc.ac.cn/zqy_portalApi/news/queryNewsPageList';

            var ARTICLE_URL = 'http://portal.catarc.ac.cn/webpages/news.html?id=';

            var param = {
                "pageNum": 1,
                "pageSize": 10,
                "title": ""
            }

            // 获取数据对象
            var content = $('#content');
            var dateStr = $('#dateStr');

            // 时间赋值
            dateStr.html(new Date().GetChineseDateStr() + '<br />' + new Date().GetChineseWeekStr());

            layui.use(['laydate'], function () {
                var laypage = layui.laypage;

                queryData(param, function (_data) {
                    laypage.render({
                        elem: 'pager'
                        , count: _data.totalSize
                        , theme: '#1E9FFF'
                        , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                        , jump: function (obj, first) {
                            console.log(obj)
                            if (!first) {
                                param.pageNum = obj.curr
                                param.pageSize = obj.limit
                                queryData(param);
                            }
                        }
                    })
                });
            })

            function queryData(_param, callback) {
                // 获取数据
                $.ajax({
                    url: DATA_URL,
                    data: JSON.stringify(_param),
                    dataType: "json",
                    contentType: "application/json;charset=utf-8",
                    type: "post",
                    success: function (data) {
                        var temp = data.data.content;
                        var contentStr = '';
                        for (var index = 0; index < temp.length; index++) {
                            const element = temp[index];
                            contentStr += "<li class='info-item'><a target='_blank'";
                            contentStr += "href='" + ARTICLE_URL + element.id + "' >" + element.title + "</a>";
                            contentStr += "<p>" + new Date(element.pubTime).Format('yyyy-MM-dd') + "</p></li>";
                        }
                        content.html(contentStr);
                        if (callback) callback(data.data);
                    }
                });
            }

        });


    </script>
</body>

</html>